﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using LibraryO2S;

public partial class Administrator_EditBanner : System.Web.UI.Page
{
    DataProcess data = new DataProcess();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            BindData(ADV_ID);

           
        }
    }

    int ADV_ID
    {
        get
        {
            return Convert.ToInt32(Request.QueryString["ADV_ID"]);
        }
    }
    public void BindData(int ADV_ID)
    {
        DataTable db = data.getAllAdvById(ADV_ID);
        txtadvName.Text = db.Rows[0]["ADV_Name"].ToString();
        txtadvlink.Text = db.Rows[0]["ADV_Link"].ToString();
        ddltarget.Text = db.Rows[0]["ADV_Target"].ToString();
        ddlstatus.Text = db.Rows[0]["ADV_Status"].ToString();
        ddlvitri.Text = db.Rows[0]["ADV_Position"].ToString();

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        

        string name = txtadvName.Text;
        string position = ddlvitri.Text;
        string link = txtadvlink.Text;
        string target = ddltarget.Text;
        string status = ddlstatus.Text;
        string filename = "";
        string txtposition = "";
        if ("Quảng Cáo Phải".Equals(position))
        {

            txtposition = "advright";

        }
        if ("Quảng Cáo Ngân Hàng".Equals(position))
        {

            txtposition = "advbottom";

        }
        if ("Quảng Cáo Giữa".Equals(position))
        {

            txtposition = "advleft";

        }
        if (fuIcon.HasFile)
        {
            filename = fuIcon.FileName;
            fuIcon.SaveAs(Server.MapPath("~/images/") + filename);

        }
        try
        {
            if (data.editAdv(name, txtposition , link,target,filename,status,ADV_ID))
            {
                divMessage.InnerHtml = O2S_Message.Success("System", "Successfully");

            }

        }
        catch (Exception ex)
        {

            divMessage.InnerHtml = O2S_Message.Error("System", "Error" + ex.Message);
        }

    }
}